#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>

int main()
{
	pid_t id = fork();
	if (id == 0) {  // child process          
		while (1) {
			printf("I am child process.....PID:%d, PPID:%d\n", getpid(), getppid());
			sleep(1);
		}
	}

	// father process        
	int status = 0;
	pid_t ret = waitpid(id, &status, 0);
	if (ret > 0) {
		// wait success                    
		printf("wait child process success\n");
		if (WIFEXITED(status)) {
			// child process exit normal                                 
			printf("child process exit code:%d\n", WEXITSTATUS(status));
		}
		if (WIFSIGNALED(status)) {
			// child process killed by signal                             
			printf("child process killed by signal %d\n", WTERMSIG(status));
		}
	}
	sleep(3);
    printf("father process quit\n");
	return 0;
}
